package day20170407;

import org.junit.Test;

public class QuickSortTest {
	
	@Test
	public void sortTest() throws Exception {
		int[] arrays = {1,2,6,4,5};
		boolean sort = sort(arrays);
		String str = sort == false ? "已经排序好了，不用进行排序" : "排序完成";
		System.out.println(str);
	}
	
	/**
	 * 
	 * @param arrays
	 */
	public boolean sort(int[] arrays){
		int temp = 0;
		//已经排序好了，不用进行排序
		boolean result = false;
		for(int i=0; i<arrays.length-1; i++){
			for(int k=0; k<arrays.length-i-1; k++){
				if(arrays[k] > arrays[k+1]){
					result = true;
					temp = arrays[k];
					arrays[k] = arrays[k+1];
					arrays[k+1] = temp;
				}
			}
		}
		if(result){
			for(int i=0; i<arrays.length; i++){
				System.out.print(arrays[i]+" ");
			}
		}
		return result;
	}
	
	
}
